/*
邀请面试对话框与查看企业联系方式
@绑定查看联系方式
 * @userName:    用户名
 * @url:        ajax回调地址
 * @interviewUrl 邀请面试状态返回地址
 * @crsf:       crsf令牌
 * @resumeId:   简历ID
 * @callBack    响应返回的状态
 * 示例
 @绑定面试邀请框
 $(".button2").click(function(){
    $.interview({userName:"",url:"",interviewUrl:"", crsf:"",resumeId: "",callBack:function(status){
            //alert(status);//0发布成功，1您今天已邀请过了，或未选择面试工作2企业未发布工作岗位
        }});
 });
*/
$(function(){
    $.extend({
        //企业发送面试邀请
        interview:function(settings){
            var setvar={
                className:"interview_button",
                crsf:"",
                url:"",
                interviewUrl:"",
                postJobUrl:"",
                resumeId:"",
                jobId:0,
                userName:"",
                callBack:function(){}
            };
            $.extend(setvar,settings);

            var toInterView = layer.open({
                type: 1,
                title:"邀请<b>["+setvar.userName+'</i>]</b>参加面试',
                skin: 'layer-interview',
                area: ['420px', '315px'],//['420px', '350px']
                resize:false,
                move:false,
                btn:false,
                content:"<div id='interviewDiv'></div>",
                success:function(){
                    $.post(setvar.url,{
                        '_token': setvar.crsf,
                        'resumeId': setvar.resumeId
                    },function (data) {
                        switch (data.status){
                            case 2:
                                html = '';
                                html += "<div class='noJobDiv'>";
                                    html += "<div class='haveNoJob'>";
                                    html += "<p class='first-tip'>您还没有发布的职位</p>";
                                    html += "<p class='second-tip'>发布职位，320万人才给您投递简历</p>";
                                    html += "<a href="+setvar.postJobUrl+" class='button' target='_blank'>立即发布职位</a>";
                                    html += "</div>";
                                html += "</div>";
                                $("#interviewDiv").html(html);
                                setvar.callBack(data.status);
                                break;
                            case 1:
                                inviteTitle = data.inviteTitle;
                                html = '';
                                //option
                                html += "<div class='interviewbox'>";
                                html += "<form action='#' method='post' name='interviewForm' id='interviewForm' >";//company/interviewnote
                                html += "<div class='jobtitle'><i>面试职位：</i>";
                                html += "<input type='hidden' name='_token' value='"+setvar.crsf+"'>";
                                html += "<input type='hidden' name='resumeId' value='"+setvar.resumeId+"'>";
                                html += "<select name='jobId' id='jobId'>";
                                html += "<option value=''>邀请面试的岗位</option>";
                                $.each( inviteTitle, function(key, value){
                                    if(setvar.jobId == key){
                                        html += "<option value='"+key+"' selected>"+value+"</option>";
                                    }else{
                                        html += "<option value='"+key+"'>"+value+"</option>";
                                    }

                                });
                                html += '</select>';
                                html += "</div>";

                                html += "<div class='interviewtime'>";
                                html += "<span><i>面试时间：</i><input class='datainp wicon timeput' id='inpstart' name='inpstart' type='text' placeholder='邀请面试时间' value='"+data.interViewTime+"' readonly></span>";
                                html += "</div>";

                                html += "<div class='jobnote'>";
                                html += "<span><i>相关备注：</i><textarea name='jobnote'></textarea></span>";
                                html += "</div>";

                                //备注


                                html += "<div class='interviewbutton'>";
                                html += "<em>*将以短信或邮件通知对方</em><input type='submit' value='发送邀请' id='checkInterView'>";
                                html += "</div>";

                                html += "</form>";

                                html += "</div>";
                                $("#interviewDiv").html(html);

                                var start = {
                                    format: 'YYYY-MM-DD hh:mm:ss',
                                    minDate: $.nowDate(0), //设定最小日期为当前日期
                                    festival:false,
                                    skinCell:"jedateInter",
                                    //isinitVal:true,
                                    maxDate: '2099-06-16 23:59:59', //最大日期
                                    fixed:true
                                };
                                $("#inpstart").jeDate(start);
                                //面试邀请表单提交
                                $("#checkInterView").click(function(){
                                    var queryString = $("#interviewForm").formSerialize();
                                    $.ajax({
                                        url: setvar.interviewUrl,
                                        dataType: "json",
                                        data: queryString,
                                        type: "POST",
                                        time: 0,
                                        success: function (data) {
                                            if(data.status == '0'){
                                                layer.msg(data.msg, {icon: 6});
                                                setvar.callBack(data.status);
                                                layer.close(toInterView);
                                                return true;
                                            }else{
                                                layer.msg(data.msg, {icon: 5});
                                                setvar.callBack(data.status);
                                                layer.close(toInterView);
                                                return false;
                                            }
                                        },
                                        error: function (data) {
                                            var msgErr='';
                                            var errors = $.parseJSON(data.responseText);
                                            $.each(errors, function(index, value) {
                                                msgErr +=  value+";<br>";
                                            });
                                            layer.msg(msgErr, {icon: 5});
                                            layer.close(toInterView);
                                        },
                                        complete: function () {
                                        }
                                    });
                                    return false;
                                });
                            break;
                        }
                    });

                }
            });

        },
        //企业查看联系方式
        getContact:function(settings){
            var setvar = {
                className:"getcontact",
                resumeId:"",//简历id
                userName:"",//简历人名称
                url:"",//url('/personcontact')
                crsf:"",
                callBack:function(){}
            };
            $.extend(setvar,settings);

            $.post(setvar.url,{
                '_token': setvar.crsf,
                'resumeId': setvar.resumeId
            },function (data) {
                var html = '';
                switch (data.status){
                    case 0:
                        //提示充值
                        html += "<div class='box'><i></i><span>亲，您的简历数已用尽。</span></div>" +
                            "<input type='button' value='关 闭' id='closeGetContact' >";
                        lookcontact = layer.open({
                            type: 1,
                            title:"<b style='color:#ffae01;'>["+setvar.userName+'</i>]</b>的联系方式',
                            skin: 'layer-getContact',
                            area: ['370px', '215px'],
                            resize:false,
                            move:false,
                            btn:false,
                            content:html
                        });
                        break;
                    case 1:
                        html += "<ul>";
                        html += "<li><span>联系电话：<i>"+data.mobile+"</i></span></li>";
                        html += "<li><span>邮箱地址：<i>"+data.email+"</i></span></li>";
                        html += "<li><span>QQ号码 ：<i>"+data.qq+"</i></span></li>";
                        html += "</ul>";
                        $(".button1").remove();
                        $('.content .baseInfo .details').append(html);

                        break;
                    case 2:
                        //提示充值
                        html += "<div class='box'><i></i><span>亲，您的会员时间已过期。</span></div>" +
                            "<input type='button' value='关 闭' id='closeGetContact' >";
                        lookcontact = layer.open({
                            type: 1,
                            title:"<b style='color:#ffae01;'>["+setvar.userName+'</i>]</b>的联系方式',
                            skin: 'layer-getContact',
                            area: ['370px', '215px'],
                            resize:false,
                            move:false,
                            btn:false,
                            content:html
                        });
                        break;
                }
                setvar.callBack(data.status);
                $("#closeGetContact").click(function(){
                    layer.close(lookcontact);
                });
            });
        }
    });
});
